package com.wokeMy.view;

import android.app.Dialog;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.woke.data.Data_bindcarlist;
import com.woke.method.MyApp;
import com.wokeMy.view.base.BaseActivity;
import com.zhongcai.online.R;


public class ZhiqingSelectActivity extends BaseActivity implements View.OnClickListener ,AdapterView.OnItemClickListener{

    EditText money_czPass_et;

    ImageView back;
    ListView cz_lv;
    TextView repaycredittexttitle,czpasstitle;

    Data_bindcarlist listdata;
    Intent intent;
    String money;
    float moneyFloat;
    int way_id,vip_level;
    String user_id,phone;
    String pay_card_no,card_no,expired_date,cvv;
    Dialog mydialog;

    Double yueMoney;
    String card;
    LayoutInflater inflater;
    String passString[]={"支付宝扫码","微信扫码"};
    int passInt[]={R.mipmap.alipayioc,R.mipmap.weipay};
    @Override
    public void setContentView() {
        setContentView(R.layout.activity_congzi_pass);
    }

    @Override
    public void initActivity() {
        back.setOnClickListener(this);
        cz_lv.setAdapter(new czAdapterterter());
        cz_lv.setOnItemClickListener(this);
        repaycredittexttitle.setText("直清");
        czpasstitle.setText("请选择直清方式");
    }

    @Override
    public void initView() {
        money_czPass_et = myFindViewById(R.id.money_czPass_et);
        cz_lv = myFindViewById(R.id.cz_lv);
        back = myFindViewById(R.id.back_czPass_iv);
        repaycredittexttitle = myFindViewById(R.id.repaycredit_text_title);
        czpasstitle = myFindViewById(R.id.cz_pass_title);
    }

    @Override
    public void initData() {
        intent=getIntent();
        way_id = intent.getIntExtra ("way_id", 0);
        //        user_id = intent.getStringExtra("user_id");
        yueMoney=0.00;
        user_id=((MyApp)getApplication()).getDatas_load().getId();
        vip_level=(Integer.parseInt(((MyApp)getApplication()).getDatas_load().getUser_type()));
        //        unionPayChannel=(UnionPayChannel)intent.getSerializableExtra("unionPayChanne");
        //        Log.e("initData",money+" "+unionPayChannel.getId()+" "+unionPayChannel.get)
        inflater=LayoutInflater.from(ZhiqingSelectActivity.this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back_czPass_iv:
                finish();
                break;
            default:
                break;
        }
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        money=money_czPass_et.getText().toString().trim();
        String s="";
        Log.e("String",s.length()+"");
        if(!money.equals("")){
            Intent intent = new Intent();
            moneyFloat = Float.parseFloat (money);
            switch (position) {
                case 0:
                    //0全部，1微信，2 支付宝
                    intent.setClass (ZhiqingSelectActivity.this,
                            ZqPassActivity.class);
                    intent.putExtra ("money", moneyFloat);
                    intent.putExtra ("type", "2");
                    startActivity (intent);
                    break;
                case 1:
                    intent.setClass (ZhiqingSelectActivity.this,
                            ZqPassActivity.class);
                    intent.putExtra ("money", moneyFloat);
                    intent.putExtra ("type", "1");
                    startActivity (intent);
                    break;
                default:
                    break;
            }
        }else{
            tishiToast("请输入金额");
        }

    }

    class czAdapterterter extends BaseAdapter{

        @Override
        public int getCount() {
            return passString.length;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Viewhold videoView;
            if (convertView==null){
                videoView=new Viewhold();
                convertView= inflater.inflate(R.layout.item_cz_pass,null);
                videoView.ivioc=(ImageView)convertView.findViewById(R.id.ioc_czpass_iv);
                videoView.tvcontent=(TextView) convertView.findViewById(R.id.content_czpass_tv);
                convertView.setTag(videoView);
            }else {
                videoView=(Viewhold)convertView.getTag();
            }
            videoView.ivioc.setBackgroundResource(passInt[position]);
            videoView.tvcontent.setText(passString[position]);
            return convertView;
        }
        class Viewhold {
            ImageView ivioc;
            TextView tvcontent;
        }
    }
}
